<?php
/*
 * 列表参数
*/
namespace App\Validation;

use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Numericality;

class ConfigsSearchValidation extends BaseValidation
{
    public function initialize()
    {

		$this->add(
			"p",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
				  ]
			)
		);
		
		$this->add(
			"page_num",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
				  ]
			)
		);
		
		$this->add(
			"key_name",
			new PresenceOf(
				  [
					  "message" => ":field is not numeric",
					  "allowEmpty" => true
				  ]
			)
		);

		$this->add(
			"order_by",
			new PresenceOf(
				  [
					  "message" => ":field is not numeric",
					  "allowEmpty" => true
				  ]
			)
		);
		
    }
	
	//验证之前
	public function beforeValidation($data, $entity, $messages)
    {
        parent::beforeValidation($data, $entity, $messages);
        
		$data->key_name = property_exists($data,'key_name') ? trim($data->key_name) : "";

        return true;
    }
	
}